package control;

import java.awt.Color;

import middlelayer.PacketBuffer;
import sniff.pack.CommonPacket;
import ui.FuncPanel;
import ui.YPSniffUI;
import ui.widget.YPUIBtn;

public class SystemUIControl {
	
	public static final String SPLITSTRING = "--------";
	
	public static int getFrameWidth() {
		return YPSniffUI.getInstance().getWidth();
	}
	
	public static void setStartStopStatus(boolean isStart) {
		Color miColor = new Color(255, 80, 80);
		YPUIBtn startStopBtn = FuncPanel.getInstance().getStartStopBtn();
		if(isStart) {
			startStopBtn.setDefaultColor(YPUIBtn.DFCOLOR);
			startStopBtn.setMouseInColor(YPUIBtn.MICOLOR);
			startStopBtn.setText("开始");
		}else {
			startStopBtn.setDefaultColor(Color.RED);
			startStopBtn.setMouseInColor(miColor);
			startStopBtn.setText("停止");
		}
	}

	public static void showPackets() {
		YPSniffUI.getInstance().getSimpleMsgPanel().removeAll();
		for (CommonPacket pack : PacketBuffer.getShowPackets()) {
			SystemUIControl.appentOnePacketToShow(pack);
		}
		YPSniffUI.getInstance().getSimpleMsgPanel().validate();
		YPSniffUI.getInstance().getSimpleMsgPanel().repaint();
		YPSniffUI.getInstance().getSimpleMsgPanel().revalidate();
	}
	
	public static void showAllPack() {
		YPSniffUI.getInstance().getSimpleMsgPanel().removeAll();
		for (CommonPacket pack : PacketBuffer.getAllPackets()) {
			SystemUIControl.appentOnePacketToShow(pack);
		}
		YPSniffUI.getInstance().getSimpleMsgPanel().validate();
		YPSniffUI.getInstance().getSimpleMsgPanel().repaint();
		YPSniffUI.getInstance().getSimpleMsgPanel().revalidate();
	}

	public static void appentOnePacketToShow(CommonPacket pack) {
		YPSniffUI.getInstance().addPackSimpleMsg(pack);
	}

}
